<?php

namespace Common;

/**
 * 数据映射模式
 *  User 类
 *
 *
 * @author	夏立军
 * @email	m17269@163.com
 * @time	2020年11月14日 11:39:20
 */
class User
{
    public $id;
    public $name;
    public $age;
    public $createtime;
    public $serail_no;


    protected $conn;

    public function __construct($id)
    {
        $this->conn = Factory::getDatabase();
        $res = $this->conn->query("SELECT * FROM `user` where id=$id LIMIT 1");
        $data = $res->fetch(\PDO::FETCH_ASSOC);
        $this->id = $data['id'];
        $this->name = $data['name'];
        $this->age = $data['age'];
        $this->createtime = $data['createtime'];
    }

    public function __destruct()
    {
        $this->conn->query("UPDATE `sjms`.`user` SET `name` = '$this->name', `age` = $this->age, `createtime` = $this->createtime, `serail_no`=$this->serail_no WHERE `id` = $this->id");
    }
}
